package com.league.zjxn.main.home

import androidx.lifecycle.LifecycleOwner
import com.blankj.utilcode.util.ActivityUtils
import com.league.zjxn.R
import com.league.zjxn.entity.ContactUs
import com.league.zjxn.jetpack.vmodel.UserViewModel
import com.module.lemlin.http.Status
import com.module.lemlin.image.loadCenterImage
import com.module.lemlin.owner.OwnerViewModeActivity
import kotlinx.android.synthetic.main.activity_contact_us.*

class ContactUsActivity : OwnerViewModeActivity<UserViewModel>() {

    companion object {
        fun open() {
            ActivityUtils.startActivity(ContactUsActivity::class.java)
        }
    }

    override fun viewModel(): UserViewModel {
        return createViewModel()
    }

    override val layoutResId: Int
        get() = R.layout.activity_contact_us

    override fun stateBar(): StatusBar {
        return StatusBar(view = flContactUsBar)
    }

    override fun initData() {
        viewModel.userContactUs()
    }

    override fun initViewMode() {
        viewModel.contactUsLiveData.observe(this as LifecycleOwner, { response ->
            if (response.status != Status.SUCCESS) {
                return@observe
            }
            val data = response.data?.data
                ?: return@observe
            fillData(data)
        })
    }

    private fun fillData(contactUs: ContactUs) {
        tvContactUsPhone.text = contactUs.phone.replace(" ","")
        tvContactUsFax.text = contactUs.fax
        tvContactUsAddress.text = contactUs.address
        ivContactUsQrCode.loadCenterImage(contactUs.qrcode)
    }

}